<template>
  <el-card class="template-card" :body-style="{ padding: '0px' }">
    <div class="image-container">
      <el-image :src="template.image" fit="cover" />
      <div class="overlay">
        <el-button type="primary" @click="handleUse">使用模板</el-button>
      </div>
    </div>
    <div class="info">
      <h3 class="title">{{ template.title }}</h3>
      <p class="description">{{ template.description }}</p>
      <div class="footer">
        <span class="author">
          <el-avatar :size="24" src="/avatar.jpg" />
          {{ template.author }}
        </span>
        <el-button text type="primary" @click="handleViewDetail">查看详情</el-button>
      </div>
    </div>
  </el-card>
</template>

<script setup lang="ts">
import { defineProps } from 'vue'
import { useRouter } from 'vue-router'

const router = useRouter()

const props = defineProps<{
  template: {
    id: number
    title: string
    description: string
    image: string
    author: string
  }
}>()

const handleUse = () => {
  router.push('/tmp')
}

const handleViewDetail = () => {
  router.push(`/template/${props.template.id}`)
}
</script>

<style scoped>
.template-card {
  border-radius: 8px;
  overflow: hidden;
  transition: transform 0.3s;
}

.template-card:hover {
  transform: translateY(-5px);
}

.image-container {
  position: relative;
  height: 200px;
}

.el-image {
  width: 100%;
  height: 100%;
}

.overlay {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  opacity: 0;
  transition: opacity 0.3s;
}

.image-container:hover .overlay {
  opacity: 1;
}

.info {
  padding: 16px;
}

.title {
  margin: 0;
  font-size: 16px;
  font-weight: bold;
}

.description {
  margin: 8px 0;
  font-size: 14px;
  color: #666;
}

.footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 12px;
}

.author {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: #666;
}
</style> 